/**
 * 
 */
package org.vsg.common.jobscheduler.vo;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.vsg.common.jobscheduler.domain.QuartzTrigger;

/**
 * @author Bill Vison
 *
 */
public class TriggerJob implements Serializable {
	
	private QuartzTrigger quartzTrigger;
	
	private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	private Calendar cale = Calendar.getInstance();
	
	public TriggerJob (QuartzTrigger trigger) {
		this.quartzTrigger = trigger;
		
	}
	
	public String getTriggerName() {
		return quartzTrigger.getId().getTriggerName();
	}
	
	public String getTriggerGroup() {
		return quartzTrigger.getId().getTriggerGroup();
	}
	
	
	public String getCode() {
		return quartzTrigger.getJobName();
	}
	
	public String getName() {
		return quartzTrigger.getDescription();
	}
	
	public String getStatus() {
		
		if (quartzTrigger.getTriggerState().equalsIgnoreCase("WAITING")) {
			return "等 待";
		}
		else if (quartzTrigger.getTriggerState().equalsIgnoreCase("PAUSED")) {
			return "停 止";
		}
		else if (quartzTrigger.getTriggerState().equalsIgnoreCase("ACQUIRED")) {
			return "初始化";
		}		
		return "";
	}
	
	public String getNextExecTime() {
		
		cale.setTimeInMillis( quartzTrigger.getNextFireTime()  );
	
		return df.format( cale.getTime() );
	}
	
	public String getStartTime() {
		cale.setTimeInMillis( quartzTrigger.getStartTime()  );
		
		return df.format( cale.getTime() );
	}

}
